/**
 * 
 */
package ihm.actions.character_creator;

import ihm.controllers.ATKcontroller;
import ihm.views.character_creator.CharacterCreator;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import systems.database.DataBaseHandler;

import characters.Characters;
import equipments.Equipment;

/**
 * @author Baptiste Legrand & Benjamin Orman
 * @version 1.0
 */
public class CreateCharacterAction
    implements ActionListener {
  
  private CharacterCreator source;
  private ATKcontroller controller;
  private Characters newCharacter;
  
  public CreateCharacterAction(CharacterCreator characterCreator)
  {
    this.source = characterCreator;
    this.controller = this.source.getController();
  }

  public void createCharacter(){
    Equipment equipment = new Equipment();
    this.newCharacter = new Characters();
    this.newCharacter.setName(this.source.getCharacterName());
    this.newCharacter.setClasse(this.source.getCharacterClasse());
    this.newCharacter.setFaction(this.source.getCharacterFaction());
    this.newCharacter.setLevel(this.source.getCharacterLevel());
    this.newCharacter.initCharacterStat(DataBaseHandler.getStatement());
    equipment.setCharacter(newCharacter);
    this.newCharacter.setEquipment(new Equipment());
    System.out.println("[CreateCharacterAction] - createCharacter - Nouveau personnage :");
    System.out.println(this.newCharacter.toString());
    System.out.println("[CreateCharacterAction] - mastery list size: "+this.newCharacter.getMasteryList().size());
  }

  /* (non-Javadoc)
   * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
   */
  @Override
  public void actionPerformed(ActionEvent e) {
    //DEBUG
    System.out.println("[CreateCharacterAction] - Debut de l'event");
    createCharacter();
    this.controller.notifyCharacterChanged(this.newCharacter);
    this.source.dispose();
    System.out.println("[CreateCharacterAction] - Fin de l'event");
  }

}
